package com.hailiang.controller;

import com.alibaba.fastjson.JSON;
import com.hailiang.dom.UnameQuery;
import com.mchange.v2.sql.filter.SynchronizedFilterDataSource;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/myservlet")
public class RegisterServlet extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        System.out.println("账号为="+username);

        String password = req.getParameter("password");
        String pnumber = req.getParameter("pnumber");
        try {
//            boolean b = new UnameQuery().queryName(username);
            UnameQuery unameQuery = new UnameQuery();


            boolean b = unameQuery.queryName(username);
            System.out.println("b="+b);

            if(b){

                System.out.println("用户已存在");
                resp.getWriter().print(0);
            }else{

               resp.getWriter().print(1);
//               点击注册再提交方法
               int i = new UnameQuery().fengzhuangData(username, password, pnumber);

            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
